/**
 * @param {string} solution
 * @param {string} guess
 * @return {number[]}
*/
var masterMind = function(solution, guess) {
  solution = solution.split("");
  guess = guess.split("");
  let result = [0, 0], solutionMap = new Map(), guessMap = new Map();
  for(let i = 0, j = 0; i < solution.length && j < guess.length; i++, j++) {
    if(solution[i] == guess[i]) {
      result[0]++;
    }
    if(solutionMap.has(solution[i])) {
      solutionMap.set(solution[i], solutionMap.get(solution[i]) + 1);
    } else {
      solutionMap.set(solution[i], 1);
    }
    if(guessMap.has(guess[i])) {
      guessMap.set(guess[i], guessMap.get(guess[i]) + 1);
    } else {
      guessMap.set(guess[i], 1);
    }
  }
  let solutionArr = [...solutionMap], guessArr = [...guessMap];
  for(let i = 0; i < solutionArr.length; i++) {
    for(let j = 0; j < guessArr.length; j++) {
      if(solutionArr[i][0] == guessArr[j][0]) {
        result[1] += Math.min(solutionArr[i][1], guessArr[j][1]);
      }
    }
  }
  result[1] -= result[0];
  return result;
};
let solution = "RGBY", guess = "GGRR";
console.log(masterMind(solution, guess));
solution="YBBY", guess = "GYYB";
console.log(masterMind(solution, guess));
